from sqlalchemy.orm import Session
from . import models, schemas

def get_music_reply(db: Session, music_reply_id: int):
    return db.query(models.MusicReply).filter(models.MusicReply.Id == music_reply_id).first()

def get_music_replies(db: Session, skip: int = 0, limit: int = 100):
    return db.query(models.MusicReply).offset(skip).limit(limit).all()

def create_music_reply(db: Session, music_reply: schemas.MusicReplyCreate):
    db_music_reply = models.MusicReply(**music_reply.dict())
    db.add(db_music_reply)
    db.commit()
    db.refresh(db_music_reply)
    return db_music_reply

def update_music_reply(db: Session, music_reply_id: int, music_reply: schemas.MusicReplyCreate):
    db_music_reply = db.query(models.MusicReply).filter(models.MusicReply.Id == music_reply_id).first()
    if db_music_reply:
        for key, value in music_reply.dict().items():
            setattr(db_music_reply, key, value)
        db.commit()
        db.refresh(db_music_reply)
    return db_music_reply

def delete_music_reply(db: Session, music_reply_id: int):
    db_music_reply = db.query(models.MusicReply).filter(models.MusicReply.Id == music_reply_id).first()
    if db_music_reply:
        db.delete(db_music_reply)
        db.commit()
    return db_music_reply